package com.dhecp.project.storage.service.impl;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.MessageUtils;
import com.dhecp.common.utils.RandomValueUtils;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.core.utils.ReflectUtils;
import com.dhecp.project.business.domain.ProductActiveComponent;
import com.dhecp.project.business.mapper.ProductActiveMapper;
import com.dhecp.project.common.domain.*;
import com.dhecp.project.common.mapper.ModuleNidAndBidMapper;
import com.dhecp.project.common.service.UpdateLogService;
import com.dhecp.project.common.service.impl.BaseModuleServiceImpl;
import com.dhecp.project.flowable.mapper.SysProcessInstanceMapper;
import com.dhecp.project.purchase.domain.OfflinePurchaseOrder;
import com.dhecp.project.purchase.domain.PurchasePlan;
import com.dhecp.project.purchase.mapper.PurchasePlanMapper;
import com.dhecp.project.storage.domain.*;
import com.dhecp.project.storage.mapper.*;
import com.dhecp.project.storage.service.ManualAssemblyService;
import com.dhecp.project.system.service.SysDictionaryForFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @program: kjecp
 * @description: 仓储 手工组装单
 * @author: hlf
 * @create: 2022-09-01 15:55
 */
@Service
public class ManualAssemblyServiceImpl extends BaseModuleServiceImpl implements ManualAssemblyService {


    @Autowired
    private ManualAssemblyMapper storageMapper;
    @Autowired
    private PurchaseStorageMapper purchaseStorageMapper;
    @Autowired
    private UpdateLogService updateLogService;

    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;
    @Autowired
    private ModuleNidAndBidMapper moduleNidAndBidMapper;
    @Autowired
    private PurchasePlanMapper purchasePlanMapper;
    @Autowired
    private ProductActiveMapper productActiveMapper;
    @Autowired
    private AssemblyMaintainMapper maintainMapper;
    @Autowired
    private ProductAssembleMapper assembleMapper;
    @Autowired
    private SysProcessInstanceMapper sysProcessInstanceMapper;
    @Autowired
    private OfflinePurchaseStorageMapper offlinePurchaseStorageMapper;
    @Autowired
    private StockControlMapper stockControlMapper;

    /**
     *@Description: 查询前一单NID、BID
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: com.dhecp.common.core.domain.AjaxResult  (data.nid 前一单NID， data.bid 前一单BID)
     *@Author: hlf
     *@date: 2022-05-09 10:08
     */
    @Override
    public AjaxResult queryLastNid(Map<String, Object> params) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        if (params.get("nid") == null || params.get("nid") == ""){
            params.put("nid", "0");
        }
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        ModuleNID moduleNID = storageMapper.selectLastNid(params);
        if (moduleNID == null){
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfirstnid"), TypeUtils.mapToJson(dataMap).toString());
        }
        dataMap.put("nid", moduleNID.getNid().toString());
        dataMap.put("bid", moduleNID.getBid().toString());
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), TypeUtils.mapToJson(dataMap).toString());
    }


    /**
     *@Description: 查询后一单NID、BID
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: com.dhecp.common.core.domain.AjaxResult  (data.nid 后一单NID， data.bid 后一单BID)
     *@Author: hlf
     *@date: 2022-05-09 10:09
     */
    @Override
    public AjaxResult queryNextNid(Map<String, Object> params) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        if (params.get("nid") == null || params.get("nid") == "" || "0".equals(params.get("nid").toString())){
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfinallynid"), TypeUtils.mapToJson(dataMap).toString());
        }
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        ModuleNID moduleNID = storageMapper.selectNextNid(params);
        if (moduleNID == null){
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfinallynid"), TypeUtils.mapToJson(dataMap).toString());
        }
        dataMap.put("nid", moduleNID.getNid().toString());
        dataMap.put("bid", moduleNID.getBid().toString());
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), TypeUtils.mapToJson(dataMap).toString());
    }


    /**
     *@Description: 查询指定单nid的首记录
     *@Param: [params]
     *@return: com.dhecp.project.storage.domain.ManualAssembly
     *@Author: hlf
     *@date: 2022-05-09 10:10
     */
    @Override
    public ManualAssembly queryFirstRecord(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        return storageMapper.selectFirstRecordByNid(params);
    }

    /**
     *@Description: 查询指定单nid的整单录
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: java.util.List<com.dhecp.project.storage.domain.ManualAssembly>
     *@Author: hlf
     *@date: 2022-05-09 10:10
     */
    @Override
    public List<ManualAssembly> queryListByNid(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        return storageMapper.selectByNid(params);
    }


    /**
     *@Description: 查询
     *@Param: [params]
     *@return: java.util.List<com.dhecp.project.storage.domain.ManualAssembly>
     *@Author: hlf
     *@date: 2022-05-09 10:10
     */
    @Override
    public List<ManualAssembly> queryList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        PageUtils.startPageStronger();
        return storageMapper.select(params);
    }

    /**
     *@Description: 查询
     *@Param: [params]
     *@return: java.util.List<com.dhecp.project.storage.domain.ManualAssembly>
     *@Author: hlf
     *@date: 2022-05-09 10:10
     */
    @Override
    public List<ManualAssembly> queryGroupList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        PageUtils.startPageStronger();
        return storageMapper.selectgroup(params);
    }

    /**
     *@Description: 保存
     *@Param: [params] moduleTable 必要参数：功能唯一标识
     *@Param: [params] infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
     *@Param: [params] infoItems 必要参数：对应实体类的json格式字符串
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 10:10
     */
    @SuppressWarnings("unchecked")
    @Override
    public AjaxResult saveData(Map<String, Object> params) {
        params.put("businessEntity", new ManualAssembly());

        AjaxResult ajaxResult = this.saveDataBase(params);
        if (!"0".equals(ajaxResult.get("code").toString())){
            throw new RuntimeException(ajaxResult.get("msg").toString());
        }

        String resNid = "0";
        Map<String, Object> infoMap = (Map<String, Object>) ajaxResult.get("infoMap");
        List<ManualAssembly> businessDataList = (List<ManualAssembly>) ajaxResult.get("businessDataList");


        List<RecordCheck> guidMapList = storageMapper.findRecords(infoMap.get("nid").toString());
        Map<String, Object> guidMap = new HashMap<String, Object>();
        if (!guidMapList.isEmpty()){
            if (infoMap.get("newNid") != null && "1".equals(infoMap.get("newNid").toString())){ //单号重复验证
                throw new RuntimeException(MessageUtils.message("module.error.retry"));
            }
            for (RecordCheck recordCheck : guidMapList){
                if (recordCheck != null && recordCheck.getGuid() != null){
                    guidMap.put(recordCheck.getGuid().toString(), "1");
                }
            }
        }

        if (businessDataList == null || businessDataList.size() == 0){
            resNid = "0";
        }else{
            resNid = infoMap.get("nid").toString();
            for (ManualAssembly businessData : businessDataList) {
                String guid = "";
                if (businessData.getGuid() == null){
                    guid = RandomValueUtils.getGUID();
                }else{
                    guid = businessData.getGuid().toString();
                }
                businessData.setGuid(guid);
                for (String field : infoMap.keySet()){ //遍历非网格字段，并赋值到实体中
                    Object fieldValue = infoMap.get(field);
                    ReflectUtils.setValue(businessData, field, fieldValue);
                }

                if (guidMap.get(guid) == null){
                    businessData.setCreateTime(new Date());
                    storageMapper.insert(businessData);
                    updateLogService.addInsertLog(params.get("moduleTable").toString(),guid,"新增");
                }else{
                    ManualAssembly oldData;
                    Map<String, Object> params2 = new HashMap<String, Object>();
                    params2.put("guid",guid);
                    oldData = storageMapper.findById(params2);

                    storageMapper.update(businessData);
                    updateLogService.addUpdateLog(params.get("moduleTable").toString(),guid,oldData,businessData,"修改");
                    guidMap.remove(guid);
                }

            }
        }

        if (!guidMap.isEmpty()){
            for (String guid : guidMap.keySet()){
                storageMapper.delete(guid);
            }
        }
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"),resNid);
    }

    /**
     *@Description: 删除
     *@Param: [params]
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 10:11
     */
    @Override
    public AjaxResult deleteData(Map<String, Object> params) {
        List<ManualAssembly> businessDataList = JSON.parseArray(params.get("infoItems").toString(), ManualAssembly.class);
        if (businessDataList == null || businessDataList.size() == 0) {
            return AjaxResult.error(MessageUtils.message("module.error.jsontoentyerror"));
        }
        for (ManualAssembly businessData : businessDataList) {
            storageMapper.delete(businessData);
        }
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
    }

    /**
     *@Description: 修改删除标志（预留）
     *@Param: [params] infoItems 必要参数：对应实体类的json格式字符串（仅需 guid 和 deleted）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 10:11
     */
    @Override
    public AjaxResult updateDeleted(Map<String, Object> params) {
        List<UpdateDeleted> updateDeletedList = JSON.parseArray(params.get("infoItems").toString(), UpdateDeleted.class);
        if (updateDeletedList == null || updateDeletedList.size() == 0) {
            return AjaxResult.error(MessageUtils.message("module.error.jsontoentyerror"));
        }
        for (UpdateDeleted updateDeleted : updateDeletedList) {
            storageMapper.updateDeleted(updateDeleted);
        }
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"));
    }

    /**
     *@Description: 流转  —— 添加流程任务、修改流程状态及生效标志
     *@Param: [params] tableDataId 必要参数：单据编码（nid）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 10:11
     */
    @Override
    public AjaxResult updateFlowGo(Map<String, Object> params) {
        Map<String, Object> infoMap = new HashMap<String, Object>();
        String nid = "0";
        if (params.get("tableDataId") == null || params.get("tableDataId") ==""){
            return AjaxResult.error(MessageUtils.message("module.error.lack","单据编码【tableDataId】"));
        }else{
            nid = params.get("tableDataId").toString();
        }
        params.put("nid", nid);
        List<ManualAssembly> businessDataList = storageMapper.selectByNid(params);
        if (businessDataList == null || businessDataList.size() == 0){
            return AjaxResult.error(MessageUtils.message("module.error.nodata"));
        }else{
            infoMap.put("cid", businessDataList.get(0).getCid());
            infoMap.put("bUser", businessDataList.get(0).getbUser());
            infoMap.put("bDept", businessDataList.get(0).getbDept());
            infoMap.put("procInstId", businessDataList.get(0).getProcInstId());
            infoMap.put("activeFlow", businessDataList.get(0).getActiveFlow());
            infoMap.put("createTime", businessDataList.get(0).getCreateTime());
            params.put("infoMap", TypeUtils.mapToJson(infoMap).toString());
            params.put("activeFlowOld", businessDataList.get(0).getActiveFlow());
        }

        //流程处理公共方法，返回单据（流转、回退等）后的流程状态信息
        if (params.get("optType") == null || params.get("optType") == ""){
            params.put("optType", "go");
        }
        UpdateFlow updateFlow = new UpdateFlow();
        updateFlow = this.FlowDealBase(params);

        for (ManualAssembly businessData : businessDataList) {
            if(updateFlow.getActiveFlow().equals("end")){//当流程结束时
                createProductAssemble(businessData);
            }
            updateFlow.setGuid(businessData.getGuid().toString());
            storageMapper.updateFlow(updateFlow);
        }

        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), nid);
    }



    /**
     *@Description: 退回  —— 添加流程任务、修改流程状态及生效标志
     *@Param: [params] tableDataId 必要参数：单据编码（nid）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 10:11
     */
    @Override
    public AjaxResult updateFlowBack(Map<String, Object> params) {
        Map<String, Object> infoMap = new HashMap<String, Object>();
        String nid = "0";
        if (params.get("tableDataId") == null || params.get("tableDataId") ==""){
            return AjaxResult.error(MessageUtils.message("module.error.lack","单据编码【tableDataId】"));
        }else{
            nid = params.get("tableDataId").toString();
        }
        params.put("nid", nid);
        List<ManualAssembly> businessDataList = storageMapper.selectByNid(params);
        if (businessDataList == null || businessDataList.size() == 0){
            return AjaxResult.error(MessageUtils.message("module.error.nodata"));
        }else{
            infoMap.put("cid", businessDataList.get(0).getCid());
            infoMap.put("bUser", businessDataList.get(0).getbUser());
            infoMap.put("bDept", businessDataList.get(0).getbDept());
            infoMap.put("procInstId", businessDataList.get(0).getProcInstId());
            infoMap.put("activeFlow", businessDataList.get(0).getActiveFlow());
            infoMap.put("createTime", businessDataList.get(0).getCreateTime());
            params.put("infoMap", TypeUtils.mapToJson(infoMap).toString());
            params.put("activeFlowOld", businessDataList.get(0).getActiveFlow());
        }

        //流程处理公共方法，返回单据（流转、回退等）后的流程状态信息
        if (params.get("optType") == null || params.get("optType") == ""){
            params.put("optType", "back");
        }
        UpdateFlow updateFlow = new UpdateFlow();
        updateFlow = this.FlowDealBase(params);

        for (ManualAssembly businessData : businessDataList) {
            updateFlow.setGuid(businessData.getGuid().toString());
            storageMapper.updateFlow(updateFlow);
        }

        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), nid);
    }


    /**
     *@Description: 根据单号查询相关数据
     *@Param: [params]
     *@return: java.util.List<com.dhecp.project.storage.domain.Putaway>
     *@Author: hlf
     *@date: 2022-12-07 17:06
     */
    @Override
    public List<ManualAssembly> selectManualAssemblyList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        return storageMapper.selectManualAssemblyList(params);
    }
    /**
     *@Description: 根据商品编码查询相关的子件库存
     *@Param: [params]
     *@return: java.util.List<com.dhecp.project.storage.domain.Putaway>
     *@Author: hlf
     *@date: 2022-12-07 17:06
     */
    @Override
    public List<ManualAssembly> selectManualAssemblyList2(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");    //查询表别名
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));    //数据权限查询条件SQL语句
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        return storageMapper.selectManualAssemblyList2(params);
    }


    //生成组装单
    private void createProductAssemble(ManualAssembly businessData) {
        try {
            //是否已生成 组装单
            List<ProductAssemble> productAssembles = assembleMapper.selectPlanID(businessData.getBid());//查询 是否已生成组装单
            if(!(productAssembles.size() >0)){
                Map<String, Object> params2 = new HashMap<String, Object>();//获取NID,BID
                params2.put("moduleTable", "TCC_PRODUCTASSEMBLE");
                params2.put("entity", new PurchaseStorage()); //用于获取实体属性名取代对应字典字段名，解决大小写敏感问题
                ModuleNidAndBid moduleNidAndBid = moduleNidAndBidMapper.findModuleNidAndBid(params2);

                Map<String, Object> assembly = new HashMap<String, Object>();//获取手工组装数据
                assembly.put("nid", businessData.getNid());
                List<ManualAssembly> manualAssemblyList = storageMapper.selectByNid(assembly);

                for (ManualAssembly item : manualAssemblyList
                     ) {
                    if (item.getQuantityRequired() > 0){
                        ProductAssemble productAssemble = new ProductAssemble();//生成新的组装单

                        List<ProductActiveComponent> productActiveComponent = new ArrayList<>();
                        productActiveComponent = productActiveMapper.queryProductActiveComponentByCode(item.getsCode());

                        AssemblyMaintain assemblyMaintain = new AssemblyMaintain(); //获取组装方案
                        assemblyMaintain = maintainMapper.findByProductID(item.getProductID());

                        if (assemblyMaintain != null) {
                            productAssemble.setBid(moduleNidAndBid.getBid());
                            productAssemble.setNid(moduleNidAndBid.getNid());
                            productAssemble.setGuid(RandomValueUtils.getGUID());
                            productAssemble.setCreateTime(new Date());
                            productAssemble.setCid(item.getCid());
                            productAssemble.setCidName(item.getCidName());
                            productAssemble.setbUser(item.getbUser());
                            productAssemble.setbUserName(item.getbUserName());
                            productAssemble.setbDept(item.getbDept());
                            productAssemble.setbDeptName(item.getbDeptName());
                            productAssemble.setaUser(item.getaUser());
                            productAssemble.setaUserName(item.getaUserName());
                            productAssemble.setaDept(item.getaDept());
                            productAssemble.setaDeptName(item.getaDeptName());
                            productAssemble.setaPosition(item.getaPosition());
                            productAssemble.setbPosition(item.getbPosition());


                            productAssemble.setProductName(item.getProductName());//商品名称
                            productAssemble.setProductID(item.getProductID());//商品编号
                            productAssemble.setvBz(productActiveComponent.get(0).getNum().toString());//商品数量
                            productAssemble.setfNSKU(item.getfNSKU());//FNSKU
                            productAssemble.setPlanID(item.getBid());//采购计划单号
                            productAssemble.setPlanNum(item.getActualNum());//计划组装数量
                            productAssemble.setActualNum(item.getActualNum());//计划组装数量
                            productAssemble.setProductNameCn(item.getName());//商品品名(中文)
                            productAssemble.setProductNameEn(item.getName());//商品品名(英文)

                            productAssemble.setaName(assemblyMaintain.getName());//组装方案
                            productAssemble.setaWay(assemblyMaintain.getWay());//组装方式
                            productAssemble.setLength(assemblyMaintain.getLength());//长度(CM)
                            productAssemble.setWidth(assemblyMaintain.getWidth());//宽度
                            productAssemble.setHeight(assemblyMaintain.getHeight());//高度
                            productAssemble.setWeight(assemblyMaintain.getWeight());//重量

                            productAssemble.setSonStorageID(item.getBid());//采购入库单号
                            Map<String, Object> params1 = new HashMap<String, Object>();//获取NID,BID
                            String code = "";
                            if (item.getRkBid().contains("CGRK")){
                                //CGRK 采购入库单
                                params1.put("wherestr","t1.bid = '"+ item.getRkBid() + "'");
                                List<PurchaseStorage> select = purchaseStorageMapper.select(params1);
                                if (select .size() != 0){
                                    code = select.get(0).getOrderID();
                                }
                            }else if (item.getRkBid().contains("XXRG")){
                                //XXRG 线下入库单
                                params1.put("wherestr","t1.bid = '"+ item.getRkBid() + "'");
                                List<OfflinePurchaseStorage> select = offlinePurchaseStorageMapper.select(params1);
                                if (select .size() != 0){
                                    code = select.get(0).getOrderID();
                                }
                            } else {
                                //数字走库存单信息
                                params1.put("wherestr","t1.purchaseStorageID = '"+ item.getRkBid() + "'");
                                List<StockControl> select = stockControlMapper.select(params1);
                                if (select .size() != 0){
                                    code = select.get(0).getPurchaseOrderID();
                                }
                            }
                            productAssemble.setSonOrderID(code);
                            productAssemble.setSonProductID(item.getsCode());//子商品编码
                            productAssemble.setSonProductName(item.getsName());//子商品名称

                            productAssemble.setSonCode(item.getsCode());//子件编码
                            productAssemble.setSonName(item.getsName());//子件名称
                            productAssemble.setSonNum(0);//子件采购总数

                            productAssemble.setsPrice(productActiveComponent.get(0).getbPrice());//子件采购单价
                            productAssemble.setRkBid(item.getRkBid());//入库Bid
                            productAssemble.setRkGuid(item.getRkGuid());//入库Guid
                            productAssemble.setvGsBm(item.getvGsBm());//公司编码
                            productAssemble.setvGsJc(item.getvGsJc());//公司简称
                            productAssemble.setvGsMc(item.getvGsMc());//公司名称
                            productAssemble.setdRkSj(item.getUpdateTime());//入库时间
                            productAssemble.setSonNum(item.getStockNum());//子件采购总数 -- 库存数量
                            productAssemble.setSonUseTotal(item.getQuantityRequired());//子件使用数量 -- 使用数量
                            productAssemble.setSonBalance(item.getQuantityRequired());//子件组装总数 -- 使用数量
                            productAssemble.setSonActualBalance(item.getStockNum()-item.getQuantityRequired());//子件剩余总数
                            productAssemble.setState("未上架");//状态 未上架/已上架/质检退回

                            //原始货位信息
                            productAssemble.setvHw(item.getGoodsAllocation());//库区
                            productAssemble.setvKq(item.getGoodsArea());//货位
                            productAssemble.setgDepot(item.getWarehouseAddress());//所在仓库

                            assembleMapper.insert(productAssemble);

//                        item.setpBid(assemblyMaintain.getName());
//                        storageMapper.update(item2);
                        }
                    }

                }

            }

        }catch (Exception ex){
            System.out.println("手工组装生成错误"+ex);
        }
    }
}